home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2012 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  63.0 KB

  1. Path: news.synopsys.com!jbuck
  2. From: jbuck@synopsys.com (Joe Buck)
  3. Newsgroups: gnu.g++.help,comp.lang.c++,news.answers,comp.answers
  4. Subject: FAQ for g++ and libg++, plain text version [Revised 15 Jan 1996]
  5. Supersedes: <g++FAQ_01_01_1996_texi@synopsys.com>
  6. Followup-To: poster
  7. Date: 15 Jan 1996 14:00:14 GMT
  8. Organization: Synopsys, Inc.
  9. Approved: news-answers-request@MIT.edu
  10. Expires: 15 Feb 1996 00:00:00 GMT
  11. Message-ID: <g++FAQ_01_15_1996_texi@synopsys.com>
  12. NNTP-Posting-Host: deerslayer.synopsys.com
  13. Originator: jbuck@deerslayer
  14.  
  15. Archive-name: g++-FAQ/plain
  16. Last-modified: 15 Jan 1996
  17. Frequency: bimonthly
  18.  
  19. [ this is the plain text version, the parent is the texinfo version ]
  20.  
  21.  
  22. FAQ for g++ and libg++, by Joe Buck (jbuck@synopsys.com)
  23. ********************************************************
  24.  
  25.    This is a list of frequently asked questions (FAQ) for g++ users;
  26. thanks to all those who sent suggestions for improvements.  Thanks to
  27. Marcus Speh for doing the index.  A hypertext version is available on
  28. the World Wide Web at `http://www.cygnus.com/misc/g++FAQ_toc.html'.
  29.  
  30.    Please send updates and corrections to the FAQ to
  31. `jbuck@synopsys.com'.  Please do *not* use me as a resource to get your
  32. questions answered; that's what gnu.g++.help is for and I don't have
  33. the time to support the net's use of g++.
  34.  
  35.    Many FAQs, including this one, are available on the archive site
  36. "rtfm.mit.edu"; see
  37. `ftp://rftm.mit.edu/pub/usenet/news.answers'.  This FAQ may be found in
  38. the subdirectory g++-FAQ.
  39.  
  40.    This FAQ is intended to supplement, not replace, Marshall Cline's
  41. excellent FAQ for the C++ language and for the newsgroup comp.lang.c++.
  42. Especially if g++ is the first C++ compiler you've ever used, the
  43. question "How do I do <X> with g++?" is probably really "How do I do
  44. <X> in C++?".  You can find this FAQ at
  45. `ftp://rtfm.mit.edu/pub/usenet/comp.lang.c++', or in HTML form at
  46. `http://cosmos2.phy.tufts.edu/~swinitzk/cppfaq/cppfa.htm'.
  47.  
  48. The latest poop - gcc-2.7.x
  49. ***************************
  50.  
  51.    This section is intended to describe more recent changes to g++,
  52. libg++, and such.  Some things in this section will eventually move
  53. elsewhere.
  54.  
  55.    As I write this, gcc-2.7.1 has just been released, followed in quick
  56. succession by gcc-2.7.2.  *Do not use version 2.7.1*, as there are a
  57. few serious problems.  I haven't had time to fully evaluate it yet, so
  58. some material below that refers to 2.7.0 may now be obsolete.
  59.  
  60.    I haven't had a lot of time to whip out this section yet, so
  61. suggestions for improvement are welcome.
  62.  
  63. g++ seems to want a const constructor.  What's that?
  64. ====================================================
  65.  
  66.    gcc-2.7.1 introduced a bug that causes the compiler to ask for a
  67. const constructor (there's no such thing in C++) in certain situations
  68. where a const object appears in a template class.  Most cases have been
  69. fixed in gcc-2.7.2, but unfortunately not all.  Still, if you're running
  70. gcc-2.7.1 and have this problem, upgrade to 2.7.2.
  71.  
  72. gcc-2.7.0 breaks declarations in "for" statements!
  73. ==================================================
  74.  
  75.    gcc-2.7.0 implements the new ANSI/ISO rule on the scope of variables
  76. declared in for loops.
  77.  
  78.      for (int i = 1; i <= 10; i++) {
  79.              // do something here
  80.      }
  81.      foo(i);
  82.  
  83.    In the above example, most existing C++ compilers would pass the
  84. value 11 to the function `foo'.  In gcc 2.7 and in the ANSI/ISO working
  85. paper, the scope of `i' is only the for loop body, so this is an error.
  86. So that old code can be compiled, the new gcc has a flag
  87. `-fno-for-scope' that causes the old rule to be used.
  88.  
  89.    As of 2.7.1, the compiler attempts to issue warnings about code that
  90. has different meanings under the two sets of rules, but the code is not
  91. perfect: the intent was that code that has valid, but different,
  92. meanings under the ARM rules and the working paper rules would give
  93. warnings but have the new behavior, and this doesn't seem to happen.
  94.  
  95.    The `-ffor-scope' flag under 2.7.1 and 2.7.2 gives the 2.7.0
  96. behavior.
  97.  
  98. What's new in version 2.7.0 of gcc/g++
  99. ======================================
  100.  
  101.    The long-awaited version 2.7.0 of gcc/g++ (along with a matching
  102. version of libg++) have now been released (now, so have 2.7.1 and
  103. 2.7.2).  This represents a great deal of work on the part of the g++
  104. maintainers to fix outstanding bugs and move the compiler closer to the
  105. current ANSI/ISO standards committee's working paper, including
  106. supporting many of the new features that have been added to the
  107. language.  I recommend that everyone read the NEWS file contained in
  108. the distribution (and that system administrators make the file
  109. available to their users).  I've borrowed liberally from this file here.
  110.  
  111.    If any features seem unfamiliar, you will probably want to look at
  112. the recently-released public review copy of the C++ Working Paper:
  113.    * PostScript and PDF (Adobe Acrobat): see
  114.      `ftp://research.att.com/dist/stdc++/WP'.
  115.  
  116.    * HTML and ASCII versions: see `ftp://ftp.cygnus.com/pub/g++'.
  117.  
  118.    * World Wide Web: see `http://www.cygnus.com/misc/wp/'.
  119.  
  120.    Here are the main points:
  121.  
  122.    * As described above, the scope of variables declared in the
  123.      initialization part of a for statement has been changed; such
  124.      variables are now visible only in the loop body.  Use
  125.      `-fno-for-scope' to get the old behavior.  You'll need this flag
  126.      to build groff version 1.09, Ptolemy, and many others.
  127.  
  128.    * Code that does not use #pragma interface/implementation will most
  129.      likely shrink dramatically, as g++ now only emits the vtable for a
  130.      class in the translation unit where its first non-inline,
  131.      non-abstract virtual function is defined.
  132.  
  133.    * Support for automatic template instantiation has *not* been enabled
  134.      in the official distribution, due to a disagreement over design
  135.      philosophies.  But you can get a patch from Cygnus to turn it on;
  136.      retrieve the patch from
  137.      `ftp://ftp.cygnus.com/pub/g++/gcc-2.7.2-repo.gz' to patch
  138.      gcc-2.7.2 (there are also patches for earlier gcc versions).
  139.  
  140.    * Support for exception handling has been improved; more targets are
  141.      now supported, and throws will use the RTTI mechanism to match
  142.      against the catch parameter type.  You must give the
  143.      `-fhandle-exceptions' to turn it on.  You must give the `-frtti'
  144.      switch to enable catching of derived exception objects with
  145.      handlers for the base exception class; if `-frtti' is not given,
  146.      only exact type matching works.
  147.  
  148.      Optimization is *not supported* with `-fhandle-exceptions'; no
  149.      need to report this as a bug.  You'll probably get an internal
  150.      compiler error if you try it.  (Q: is this better in 2.7.1?).
  151.  
  152.      For exception handling to work with 2.7.0 your CPU must be a SPARC,
  153.      RS6000/PowerPC, 386/486/Pentium, or ARM.  Release 2.7.1 added
  154.      support for the Alpha, and "m68k is rumored to work on some
  155.      platforms" and "VAX may also work" (according to Mike Stump).  It
  156.      still doesn't work on HP-PA or MIPS platforms.
  157.  
  158.    * Support for Run-Time Type Identification has been added with
  159.      `-frtti'.  This support is still in alpha; one major restriction
  160.      is that any file compiled with `-frtti' must include `<typeinfo>'
  161.      (*not* `typeinfo.h' as the NEWS file says).  Also, all code you
  162.      link with (including libg++) has to be built with `-frtti', so
  163.      it's still tricky to use.
  164.  
  165.    * Synthesis of compiler-generated constructors, destructors and
  166.      assignment operators is now deferred until the functions are used.
  167.  
  168.    * The parsing of expressions such as `a ? b : c = 1' has changed from
  169.      `(a ? b : c) = 1' to `a ? b : (c = 1)'.  This is a new C/C++
  170.      incompatibility brought to you by the ANSI/ISO standards committee.
  171.  
  172.    * The operator keywords and, and_eq, bitand, bitor, compl, not,
  173.      not_eq, or, or_eq, xor and xor_eq are now supported.  Use `-ansi'
  174.      or `-foperator-names' to enable them.
  175.  
  176.    * The `explicit' keyword is now supported.  `explicit' is used to
  177.      mark constructors and type conversion operators that should not be
  178.      used implicitly.
  179.  
  180.    * Handling of user-defined type conversion has been improved.
  181.  
  182.    * Explicit instantiation of template methods is now supported.  Also,
  183.      `inline template class foo<int>;' can be used to emit only the
  184.      vtable for a template class.
  185.  
  186.    * With -fcheck-new, g++ will check the return value of all calls to
  187.      operator new, and not attempt to modify a returned null pointer.
  188.  
  189.    * collect2 now demangles linker output, and c++filt has become part
  190.      of the gcc distribution.
  191.  
  192.    * Improvements to template instantiation: only members actually used
  193.      are instantiated.
  194.  
  195. How do I use the new repository code?
  196. =====================================
  197.  
  198.    Because there is some disagreement about the details of the template
  199. repository mechanism, you'll need to obtain a patch from Cygnus Support
  200. to enable the 2.7.2 repository code.  You can obtain the patch by
  201. anonymous FTP: `ftp://ftp.cygnus.com/pub/g++/gcc-2.7.2-repo.gz'.
  202.  
  203.    There are patches for 2.7.0 and 2.7.1 in the same directory, though
  204. if you're going to rebuild the compiler you should use the latest one.
  205.  
  206.    After you've applied the patch, the `-frepo' flag will enable the
  207. repository mechanism.  The flag works much like the existing
  208. `-fno-implicit-templates' flag, except that auxiliary files, with an
  209. `.rpo' extension, are built that specify what template expansions are
  210. needed.  At link time, the (patched) collect program detects missing
  211. templates and recompiles some of the object files so that the required
  212. templates are expanded.
  213.  
  214.    Note that the mechanism differs from that of cfront in that template
  215. definitions still must be visible at the point where they are to be
  216. expanded.  No assumption is made that `foo.C' contains template
  217. definitions corresponding to template declarations in `foo.h'.
  218.  
  219.    Jason Merrill writes: "To perform closure on a set of objects, just
  220. try to link them together.  It will fail, but as a side effect all
  221. needed instances will be generated in the objects."
  222.  
  223. Known bugs and problems with the repo patch
  224. *******************************************
  225.  
  226.    "The `-frepo' won't expand templated friend functions!"
  227.  
  228.    This is a known bug; currently you'll have to explicitly instantiate
  229. friend functions when using `-frepo' due to this bug (in 2.7.0 through
  230. 2.7.2 at least).
  231.  
  232.    With earlier versions of the repo patch, there was a bug that happens
  233. when you have given a quoted command line switch, something like
  234.  
  235.      -D'MESSAGE="hello there"'
  236.  
  237.    The repo code tries to recompile files using the same flags you
  238. originally specified, but doesn't quote arguments that need quoting,
  239. resulting in failures in some cases.  This is no longer a problem with
  240. the 2.7.2 patch.
  241.  
  242. The GNU Standard C++ Library
  243. ============================
  244.  
  245.    The GNU Standard C++ Library (also called the "GNU ANSI C++ Library"
  246. in places in the code) is not libg++, though it is included in the
  247. libg++ distribution.  Rather, it contains classes and functions
  248. required by the ANSI/ISO standard.  The copyright conditions are the
  249. same as those for for the iostreams classes; the LGPL is not used.  See
  250. *Note legalities::.
  251.  
  252.    This library, libstdc++, is in the libg++ distribution in versions
  253. 2.6.2 and later.  It requires at least gcc 2.6.3 to build the
  254. libg++-2.6.2 version; use at least gcc 2.7.0 to build the libg++ 2.7.0
  255. version.  It contains a hacked-up version of HP's implementation of the
  256. Standard Template Library (see *Note Standard Template Library::).  I've
  257. successfully used this Standard Template Library version to build a
  258. number of the demos you'll see on various web pages.
  259.  
  260.    As of version 2.7.0, the streams classes are now in libstdc++
  261. instead of libg++, and libiostream is being phased out (don't use it).
  262. The g++ program searches this library.
  263.  
  264. Obtaining Source Code
  265. *********************
  266.  
  267. What is the latest version of gcc, g++, and libg++?
  268. ===================================================
  269.  
  270.    The latest "2.x" version of gcc/g++ is 2.7.2, released November 26,
  271. 1995.  The latest version of libg++ is 2.7.1, released November 12,
  272. 1995.
  273.  
  274.    Don't use 2.5.x, with x less than 5, for C++ code; there were some
  275. serious bugs that didn't have easy workarounds.  2.5.8 is the most
  276. solid 2.5.x release.  2.6.3 is the most solid 2.6.x release.
  277.  
  278.    For some non-Unix platforms, the latest port of gcc may be an earlier
  279. version (2.5.8, say).  You'll need to use a version of libg++ that has
  280. the same first two digits as the compiler version, e.g. use libg++
  281. 2.5.x (for the latest x you can find) with gcc version 2.5.8.
  282.  
  283.    The latest "1.x" version of gcc is 1.42, and the latest "1.x"
  284. version of g++ is 1.42.0.  While gcc 1.42 is quite usable for C
  285. programs, I recommend against using g++ 1.x except in special
  286. circumstances (and I can't think of any such circumstances).
  287.  
  288. How do I get a copy of g++ for Unix?
  289. ====================================
  290.  
  291.    First, you may already have it if you have gcc for your platform;
  292. g++ and gcc are combined now (as of gcc version 2.0).
  293.  
  294.    You can get g++ from a friend who has a copy, by anonymous FTP or
  295. UUCP, or by ordering a tape or CD-ROM from the Free Software Foundation.
  296.  
  297.    The Free Software Foundation is a nonprofit organization that
  298. distributes software and manuals to raise funds for more GNU
  299. development.  Getting your copy from the FSF contributes directly to
  300. paying staff to develop GNU software.  CD-ROMs cost $400 if an
  301. organization is buying, or $100 if an individual is buying.  Tapes cost
  302. around $200 depending on media type.  I recommend asking for version 2,
  303. not version 1, of g++.
  304.  
  305.    For more information about ordering from the FSF, contact
  306. gnu@prep.ai.mit.edu, phone (617) 542-5942 or anonymous ftp file
  307. `ftp://prep.ai.mit.edu/pub/gnu/GNUinfo/ORDERS' (you can also use one of
  308. the sites listed below if you can't get into "prep").
  309.  
  310.    Here is a list of anonymous FTP archive sites for GNU software.  If
  311. no directory is given, look in `/pub/gnu'.
  312.  
  313.      ASIA: ftp.cs.titech.ac.jp, utsun.s.u-tokyo.ac.jp:/ftpsync/prep,
  314.      cair.kaist.ac.kr, ftp.nectec.or.th:/pub/mirrors/gnu
  315.      
  316.      AUSTRALIA: archie.oz.au:/gnu (archie.oz or archie.oz.au for ACSnet)
  317.      
  318.      AFRICA: ftp.sun.ac.za
  319.      
  320.      MIDDLE-EAST: ftp.technion.ac.il:/pub/unsupported/gnu
  321.      
  322.      EUROPE: irisa.irisa.fr, ftp.univ-lyon1.fr, ftp.mcc.ac.uk,
  323.      unix.hensa.ac.uk:/pub/uunet/systems/gnu, ftp.denet.dk,
  324.      src.doc.ic.ac.uk:/gnu, ftp.eunet.ch, nic.switch.ch:/mirror/gnu,
  325.      ftp.informatik.rwth-aachen.de, ftp.informatik.tu-muenchen.de,
  326.      ftp.win.tue.nl, ftp.funet.fi, ftp.denet.dk, ftp.stacken.kth.se,
  327.      isy.liu.se, ftp.luth.se:/pub/unix/gnu, ftp.sunet.se, archive.eu.net
  328.      
  329.      SOUTH AMERICA: ftp.unicamp.br, ftp.inf.utfsm.cl
  330.      
  331.      WESTERN CANADA: ftp.cs.ubc.ca:/mirror2/gnu
  332.      
  333.      USA: wuarchive.wustl.edu:/systems/gnu, labrea.stanford.edu,
  334.      ftp.digex.net:/pub/gnu, ftp.kpc.com:/pub/mirror/gnu, f.ms.uky.edu:/pub3/gnu,
  335.      jaguar.utah.edu:/gnustuff, ftp.hawaii.edu:/mirrors/gnu,
  336.      uiarchive.cso.uiuc.edu:/pub/gnu, ftp.cs.columbia.edu:/archives/gnu/prep,
  337.      col.hp.com:/mirrors/gnu, gatekeeper.dec.com:/pub/GNU,
  338.      ftp.uu.net:/systems/gnu
  339.  
  340.    The "official site" is prep.ai.mit.edu, but your transfer will
  341. probably go faster if you use one of the above machines.
  342.  
  343.    Most GNU utilities are compressed with "gzip", the GNU compression
  344. utility.  All GNU archive sites should have a copy of this program,
  345. which you will need to uncompress the distributions.
  346.  
  347.    UUNET customers can get GNU sources from UUNET via UUCP.  UUCP-only
  348. sites can get GNU sources by "anonymous UUCP" from site "osu-cis" at
  349. Ohio State University.  You pay for the long-distance call to OSU; the
  350. price isn't too bad on weekends at 9600 bps.  Send mail to
  351. uucp@cis.ohio-state.edu or osu-cis!uucp for more information.
  352.  
  353.    OSU lines are often busy.  If you're in the USA, and are willing to
  354. spend more money, you can get sources via UUCP from UUNET using their
  355. 900 number: 1-900-GOT-SRCS (900 numbers don't work internationally).
  356. You will be billed $0.50/minute by your phone company.
  357.  
  358.    Don't forget to retrieve libg++ as well!
  359.  
  360. Getting gcc/g++ for the HP Precision Architecture
  361. =================================================
  362.  
  363.    If you use the HP Precision Architecture (HP-9000/7xx and
  364. HP-9000/8xx) and you want to use debugging, you'll need to use the GNU
  365. assembler, GAS (version 2.3 or later).  If you build from source, you
  366. must tell the configure program that you are using GAS or you won't get
  367. debugging support.  A non-standard debug format is used, since until
  368. recently HP considered their debug format a trade secret.  Thanks to
  369. the work of lots of good folks both inside and outside HP, the company
  370. has seen the error of its ways and has now released the required
  371. information.  The team at the University of Utah that did the gcc port
  372. now has code that understands the native HP format.
  373.  
  374.    Some enhancements for the HP that haven't been integrated back into
  375. the official GCC are available from the University of Utah, site
  376. jaguar.cs.utah.edu.  You can retrieve sources and prebuilt binaries for
  377. GCC, GDB, binutils,and libg++; see the directory `/dist'.
  378.  
  379.    The libg++ version is actually the same as the FSF 2.6.  The Utah
  380. version of GDB can now understand both the GCC and HP C compiler debug
  381. formats, so it is no longer necessary to have two different GDB
  382. versions.
  383.  
  384.    I recommend that HP users use the Utah versions of the tools (see
  385. above), though at this point the standard FSF versions will work well.
  386.  
  387.    HP GNU users can also find useful stuff on the site geod.emr.ca in
  388. the `/pub/UNIX/GNU-HP' directory.
  389.  
  390.    Jeff Law is leaving the University of Utah, so the Utah prebuilt
  391. binaries may be discontinued.
  392.  
  393. Getting gcc/g++ binaries for Solaris 2.x
  394. ========================================
  395.  
  396.    "Sun took the C compiler out of Solaris 2.x.  Am I stuck?"
  397.  
  398.    No; prep.ai.mit.edu and its mirror sites provide GCC binaries for
  399. Solaris.  As a rule, these binaries are not updated as often as the
  400. sources are, so if you want the very latest version of gcc/g++, you may
  401. need to grab and install binaries for an older version and use it to
  402. bootstrap the latest version from source.
  403.  
  404.    The latest gcc binaries on prep.ai.mit.edu and its mirror sites are
  405. for version 2.5.6 for Solaris on the Sparc, and version 2.4.5 for
  406. Solaris on Intel 386/486 machines (the Solaris/Intel binaries seem to
  407. be gone from prep but still exist on some mirrors).
  408.  
  409.    There are also binaries for "gzip", the GNU compression utility,
  410. which you'll need for uncompressing the binary distribution.  On any GNU
  411. archive site, look in subdirectories `i486-sun-solaris2' or
  412. `sparc-sun-solaris2'.
  413.  
  414.    The ftp directory `ftp://ftp.quintus.com/pub/GNU' contains various
  415. GNU and freeware programs for Solaris2.X running on the sparc. These are
  416. packaged to enable installation using the Solaris "pkgadd" utility.
  417. These include GNU emacs 19.27, gcc (and g++) 2.6.0, Perl 4.036, and
  418. others.
  419.  
  420. How do I get a copy of g++ for (some other platform)?
  421. =====================================================
  422.  
  423.    As of gcc-2.7.x, there is some Windows NT support in gcc.  Some
  424. special utilities are required.  See the INSTALL file from the
  425. distribution.
  426.  
  427.    The standard gcc/g++ distribution includes VMS support.  Since the
  428. FSF people don't use VMS, it's likely to be somewhat less solid than
  429. the Unix version.  Precompiled copies of g++ and libg++ in
  430. VMS-installable form are available by FTP from mango.rsmas.miami.edu.
  431. See also `ftp://ftp.stacken.kth.se/pub/GNU-VMS/contrib', the site (in
  432. Sweden) which has gcc-2.5.8 and libg++-2.5.3.
  433.  
  434.    There are two different versions of gcc/g++ for MS-DOS: EMX and
  435. DJGPP.  EMX also works for OS/2 and is described later.  DJGPP is DJ
  436. Delorie's port.  It can be found on many FTP archive sites; its "home"
  437. is `ftp://oak.oakland.edu/pub/msdos/djgpp/'.
  438.  
  439.    The latest version of DJGPP is 1.12.maint4, a port of gcc-2.6.3 plus
  440. support software.  This version runs under Windows 3.x.  There's also a
  441. beta-2.00 version.
  442.  
  443.    FSF sells floppies with DJGPP on them; see above for ordering
  444. software from the FSF.
  445.  
  446.    DJGPP has its own newsgroup: `news:comp.os.msdos.djgpp'.
  447.  
  448.    For information on Amiga ports of gcc/g++, retrieve the file
  449. `ftp://prep.ai.mit.edu/pub/gnu/MicrosPorts/Amiga' or write to Markus M.
  450. Wild <wild@nessie.cs.id.ethz.ch>, who I hope won't be too upset that I
  451. mentioned his name here.
  452.  
  453.    A port of gcc to the Atari ST can be found at
  454. `ftp://atari.archive.umich.edu/atari/Gnustuff/Tos' along with many
  455. other GNU programs.  This version is usually the same as the latest FSF
  456. release.  See the "Software FAQ" for the Usenet group
  457. "comp.sys.atari.st" for more information.
  458.  
  459.    There are two different ports of gcc to OS/2, the so-called EMX port
  460. (which also runs on MS-DOS), and a port called "gcc/2".  The latter
  461. port is no longer supported, since the EMX port includes all of its
  462. functionality.  The EMX port's C library attempts to provide a
  463. Unix-like environment.  For more information ask around on
  464. "comp.os.os2.programmer.misc".
  465.  
  466.    The EMX port is available by FTP from
  467.  
  468.      ftp://ftp.uni-stuttgart.de/pub/systems/os2/emx-0.9a
  469.      ftp://src.doc.ic.ac.uk/pub/packages/os2/unix/emx09a
  470.      ftp://ftp.informatik.tu-muenchen.de/pub/comp/os/os2/devtools/emx+gcc
  471.  
  472.    Eberhard Mattes did the EMX port.  His address is
  473. mattes@azu.informatik.uni-stuttgart.de.
  474.  
  475.    I'm looking for more information on gcc/g++ support on the Apple
  476. Macintosh.  Until recently, this FAQ did not provide such information,
  477. but FSF is no longer boycotting Apple as the League for Programming
  478. Freedom boycott has been dropped.
  479.  
  480.    Versions 1.37.1 and 2.3.3 of gcc were ported by Stan Shebs and are
  481. available at
  482. `ftp://ftp.cygnus.com/pub/mac'
  483.  
  484.    They are both interfaced to MPW.  Stan is working on a version using
  485. the current (post-2.7) sources, contact him directly (shebs@cygnus.com)
  486. for more information.
  487.  
  488. But I can only find g++-1.42!
  489. =============================
  490.  
  491.    "I keep hearing people talking about g++ 2.7.2 (or some other number
  492. starting with 2), but the latest version I can find is g++ 1.42.  Where
  493. is it?"
  494.  
  495.    As of gcc 2.0, C, C++, and Objective-C as well are all combined into
  496. a single distribution called gcc.  If you get gcc you already have g++.
  497. The standard installation procedure for any gcc version 2 compiler will
  498. install the C++ compiler as well.
  499.  
  500.    One could argue that we shouldn't even refer to "g++-2.x.y" but it's
  501. a convention.  It means "the C++ compiler included with gcc-2.x.y."
  502.  
  503. Installation Issues and Problems
  504. ********************************
  505.  
  506. I can't build g++ 1.x.y with gcc-2.x.y!
  507. =======================================
  508.  
  509.    "I obtained gcc-2.x.y and g++ 1.x.y and I'm trying to build it, but
  510. I'm having major problems.  What's going on?"
  511.  
  512.    If you wish to build g++-1.42, you must obtain gcc-1.42 first.  The
  513. installation instructions for g++ version 1 leave a lot to be desired,
  514. unfortunately, and I would recommend that, unless you have a special
  515. reason for needing the 1.x compiler, that C++ users use the latest
  516. g++-2.x version, as it is the version that is being actively maintained.
  517.  
  518.    There is no template support in g++-1.x, and it is generally much
  519. further away from the ANSI draft standard than g++-2.x is.
  520.  
  521. OK, I've obtained gcc; what else do I need?
  522. ===========================================
  523.  
  524.    First off, you'll want libg++ as you can do almost nothing without it
  525. (unless you replace it with some other class library).
  526.  
  527.    Second, depending on your platform, you may need "GAS", the GNU
  528. assembler, or the GNU linker (see next question).
  529.  
  530.    Finally, while it is not required, you'll almost certainly want the
  531. GNU debugger, gdb.  The latest version is 4.15.1, released November 4,
  532. 1995.  Other debuggers (like dbx, for example) will normally not be
  533. able to understand at least some of the debug information produced by
  534. g++.
  535.  
  536. Should I use the GNU linker, or should I use "collect"?
  537. =======================================================
  538.  
  539.    First off, for novices: special measures must be taken with C++ to
  540. arrange for the calling of constructors for global or static objects
  541. before the execution of your program, and for the calling of
  542. destructors at the end.  (Exception: System VR3 and System VR4 linkers,
  543. Linux/ELF, and some other systems support user-defined segments; g++ on
  544. these systems requires neither the GNU linker nor collect.  So if you
  545. have such a system, the answer is that you don't need either one).
  546.  
  547.    If you have experience with AT&T's "cfront", this function is
  548. performed there by programs named "patch" or "munch".  With GNU C++, it
  549. is performed either by the GNU linker or by a program known as
  550. "collect".  The collect program is part of the gcc-2.x distribution;
  551. you can obtain the GNU linker separately as part of the "binutils"
  552. package.  The latest version of binutils is 2.5.2, released November 2,
  553. 1994.
  554.  
  555.    (To be technical, it's "collect2"; there were originally several
  556. alternative versions of collect, and this is the one that survived).
  557.  
  558.    There are advantages and disadvantages to either choice.
  559.  
  560.    Advantages of the GNU linker:
  561.  
  562.    It's faster than using collect - collect basically runs the standard
  563. Unix linker on your program twice, inserting some extra code after the
  564. first pass to call the constructors.  This is a sizable time penalty
  565. for large programs.  The GNU linker does not require this extra pass.
  566.  
  567.    GNU ld reports undefined symbols using their true names, not the
  568. mangled names (but as of 2.7.0 so does collect).
  569.  
  570.    If there are undefined symbols, GNU ld reports which object file(s)
  571. refer to the undefined symbol(s).
  572.  
  573.    As of binutils version 2.2, on systems that use the so-called "a.out"
  574. debug format (e.g. Suns running SunOS 4.x), the GNU linker compresses
  575. the debug symbol table considerably.
  576.  
  577.    Advantages of collect:
  578.  
  579.    If your native linker supports shared libraries, you can use shared
  580. libraries with collect.  This used to be a strong reason *not* to use
  581. the GNU linker, but recent versions of GNU ld support linking with
  582. shared libraries on many platforms, and creating shared libraries on a
  583. few (such as Intel x86 systems that use ELF object format).
  584.  
  585.    Note: using existing shared libraries (X and libc, for example) works
  586. very nicely.  Generating shared libraries from g++-compiled code is
  587. another matter, generally requiring OS-dependent tricks if it is
  588. possible at all.  But progress has been made recently.
  589.  
  590.    As of 2.7.0, building C++ shared libraries should work fine on
  591. supported platforms (HPUX 9+, IRIX 5+, DEC UNIX (formerly OSF/1), SunOS
  592. 4, Linux/ELF and all targets using SVR4-style ELF shared libraries).
  593.  
  594.    However, as of libg++ 2.6.2, the libg++ distribution contains some
  595. patches to build libg++ as a shared library on some OSes (those listed
  596. above).  Check the file `README.SHLIB' from that distribution.
  597.  
  598.    The GNU linker has not been ported to as many platforms as g++ has,
  599. so you may be forced to use collect.
  600.  
  601.    If you use collect, you don't need to get something extra and figure
  602. out how to install it; the standard gcc installation procedure will do
  603. it for you.
  604.  
  605.    In conclusion, I don't see a clear win for either alternative at this
  606. point.  Take your pick.
  607.  
  608. Should I use the GNU assembler, or my vendor's assembler?
  609. =========================================================
  610.  
  611.    This depends on your platform and your decision about the GNU
  612. linker.  For most platforms, you'll need to use GAS if you use the GNU
  613. linker.  For some platforms, you have no choice; check the gcc
  614. installation notes to see whether you must use GAS.  But you can
  615. usually use the vendor's assembler if you don't use the GNU linker.
  616.  
  617.    The GNU assembler assembles faster than many native assemblers;
  618. however, on many platforms it cannot support the local debugging format.
  619.  
  620.    If you want to build shared libraries from gcc/g++ output and you
  621. are on a Sun, you must *not* use GNU as, as it cannot do
  622. position-independent code correctly yet.  *Note*: I've been told that
  623. this problem has been fixed in the most recent binutils release, but I
  624. haven't checked this yet.
  625.  
  626.    On HPUX or IRIX, you must use GAS (and configure gcc with the
  627. `--with-gnu-as' option) to debug your programs.  GAS is strongly
  628. recommended particularly on the HP platform because of limitations in
  629. the HP assembler.
  630.  
  631.    The GAS distribution has recently been merged with the binutils
  632. distribution, so the GNU assembler and linker are now together in this
  633. package (as of binutils version 2.5.1).
  634.  
  635. Should I use the GNU C library?
  636. ===============================
  637.  
  638.    At this point in time, no.  The GNU C library is still very young,
  639. and libg++ still conflicts with it in some places.  Use your native C
  640. library unless you know a lot about the gory details of libg++ and
  641. gnu-libc.  This will probably change in the future.
  642.  
  643. Global constructors aren't being called
  644. =======================================
  645.  
  646.    "I've installed gcc and it almost works, but constructors and
  647. destructors for global objects and objects at file scope aren't being
  648. called.  What did I do wrong?"
  649.  
  650.    It appears that you are running on a platform that requires you to
  651. install either "collect2" or the GNU linker, and you have done neither.
  652. For more information, see the section discussing the GNU linker (*Note
  653. use GNU linker?::).
  654.  
  655.    On Solaris 2.x, you shouldn't need a collect program and GNU ld
  656. doesn't run.  If your global constructors aren't being called, you may
  657. need to install a patch, available from Sun, to fix your linker.  The
  658. number of the "jumbo patch" that applies is 101409-03.  Thanks to
  659. Russell Street (r.street@auckland.ac.nz) for this info.
  660.  
  661.    It appears that on IRIX, the collect2 program is not being installed
  662. by default during the installation process, though it is required; you
  663. can install it manually by executing
  664.  
  665.      make install-collect2
  666.  
  667.    from the gcc source directory after installing the compiler.  (I'm
  668. not certain for which versions of gcc this problem occurs, and whether
  669. it is still present).
  670.  
  671. Strange assembler errors when linking C++ programs
  672. ==================================================
  673.  
  674.    "I've installed gcc and it seemed to go OK, but when I attempt to
  675. link any C++ program, I'm getting strange errors from the assembler!
  676. How can that be?"
  677.  
  678.    The messages in question might look something like
  679.  
  680.      as: "/usr/tmp/cca14605.s", line 8: error: statement syntax
  681.      as: "/usr/tmp/cca14605.s", line 14: error: statement syntax
  682.  
  683.    (on a Sun, different on other platforms).  The important thing is
  684. that the errors come out at the link step, *not* when a C++ file is
  685. being compiled.
  686.  
  687.    Here's what's going on: the collect2 program uses the Unix "nm"
  688. program to obtain a list of symbols for the global constructors and
  689. destructors, and it builds a little assembly language module that will
  690. permit them all to be called.  If you're seeing this symptom, you have
  691. an old version of GNU nm somewhere on your path.  This old version
  692. prints out symbol names in a format that the collect2 program does not
  693. expect, so bad assembly code is generated.
  694.  
  695.    The solution is either to remove the old version of GNU nm from your
  696. path (and that of everyone else who uses g++), or to install a newer
  697. version (it is part of the GNU "binutils" package).  Recent versions of
  698. GNU nm do not have this problem.
  699.  
  700. Other problems building libg++
  701. ==============================
  702.  
  703.    "I am having trouble building libg++.  Help!"
  704.  
  705.    On some platforms (for example, Ultrix), you may see errors
  706. complaining about being unable to open dummy.o.  On other platforms
  707. (for example, SunOS), you may see problems having to do with the type
  708. of size_t.  The fix for these problems is to make libg++ by saying
  709. "make CC=gcc".  According to Per Bothner, it should no longer be
  710. necessary to specify "CC=gcc" for libg++-2.3.1 or later.
  711.  
  712.    "I built and installed libg++, but g++ can't find it.  Help!"
  713.  
  714.    The string given to `configure' that identifies your system must be
  715. the same when you install libg++ as it was when you installed gcc.
  716. Also, if you used the `--prefix' option to install gcc somewhere other
  717. than `/usr/local', you must use the same value for `--prefix' when
  718. installing libg++, or else g++ will not be able to find libg++.
  719.  
  720.    The toplevel Makefile in the libg++ 2.6.2 distribution is broken,
  721. which along with a bug in g++ 2.6.3 causes problems linking programs
  722. that use the libstdc++ complex classes.  A patch for this is available
  723. from `ftp://ftp.cygnus.com//pub/g++/libg++-2.6.2-fix.gz'.
  724.  
  725. But I'm *still* having problems with `size_t'!
  726. ==============================================
  727.  
  728.    "I did all that, and I'm *still* having problems with disagreeing
  729. definitions of size_t, SIZE_TYPE, and the type of functions like
  730. `strlen'."
  731.  
  732.    The problem may be that you have an old version of `_G_config.h'
  733. lying around.  As of libg++ version 2.4, `_G_config.h', since it is
  734. platform-specific, is inserted into a different directory; most include
  735. files are in `$prefix/lib/g++-include', but this file now lives in
  736. `$prefix/$arch/include'.  If, after upgrading your libg++, you find that
  737. there is an old copy of `_G_config.h' left around, remove it, otherwise
  738. g++ will find the old one first.
  739.  
  740. Do I need to rebuild libg++ to go with my new g++?
  741. ==================================================
  742.  
  743.    "After I upgraded g++ to the latest version, I'm seeing undefined
  744. symbols."
  745.  
  746.    or
  747.  
  748.    "If I upgrade to a new version of g++, do I need to reinstall
  749. libg++?"
  750.  
  751.    As a rule, the first two digits of your g++ and libg++ should be the
  752. same.  Normally when you do an upgrade in the "minor version number"
  753. (2.5.7 to 2.5.8, say) there isn't a need to rebuild libg++, but there
  754. have been a couple of exceptions in the past.
  755.  
  756. Trouble installing g++ and libg++ on Linux
  757. ******************************************
  758.  
  759.    "I've downloaded the latest g++ and libg++ and I'm trying to install
  760. them on Linux, and I'm having lots of problems."
  761.  
  762.    FSF releases of libg++ won't install on Linux unchanged, since Linux
  763. uses are part of the libio library from libg++ for its standard C
  764. library, only this is changed in a way that it clashes with libg++.
  765. This means that you'll need a patched version of libg++ for it to work.
  766.  
  767.    If you want to upgrade to a new gcc/libg++ combination, the easiest
  768. thing to do is to grab the prebuilt versions of gcc and libg++ for Linux
  769. from `ftp://tsx-11.mit.edu/pub/linux/packages/GCC'.  Follow the
  770. directions carefully.  If you want to build from source, you'll need a
  771. patch for libg++; the Linux developers have named the patched libg++
  772. version libg++-2.7.1.3 and there is a patch file in the above-named
  773. directory.
  774.  
  775.    See `ftp://www.mrc-apu.cam.ac.uk/pub/linux/GCC-FAQ.html', the Linux
  776. GCC FAQ (though it may be a bit out of date; the Linux community moves
  777. quickly).
  778.  
  779. Problems with g++ on Linux Slackware 3.0
  780. ****************************************
  781.  
  782.    "When I try to compile the traditional Hello, world program on Linux,
  783. the compiler can't find `iostream.h'.  What's the deal?"
  784.  
  785.    You probably have the Slackware 3.0 release.  There's an error in the
  786. setup.  It's easy to fix, though; log in as root, and make a symbolic
  787. link:
  788.  
  789.      ln -s /usr/lib/g++-include /usr/include/g++
  790.  
  791. User Problems
  792. *************
  793.  
  794. How to silence "unused parameter" warnings
  795. ==========================================
  796.  
  797.    "When I use `-Wall' (or `-Wunused'), g++ warns about unused
  798. parameters.  But the parameters have to be there, for use in derived
  799. class functions.  How do I get g++ to stop complaining?"
  800.  
  801.    The answer is to simply omit the names of the unused parameters when
  802. defining the function.  This makes clear, both to g++ and to readers of
  803. your code, that the parameter is unused.  For example:
  804.  
  805.      int Foo::bar(int arg) { return 0; }
  806.  
  807.    will give a warning for the unused parameter `arg'.  To suppress the
  808. warning write
  809.  
  810.      int Foo::bar(int) { return 0; }
  811.  
  812. g++ objects to a declaration in a case statement
  813. ================================================
  814.  
  815.    "The compiler objects to my declaring a variable in one of the
  816. branches of a case statement.  Earlier versions used to accept this
  817. code.  Why?"
  818.  
  819.    The draft standard does not allow a goto or a jump to a case label to
  820. skip over an initialization of a variable or a class object.  For
  821. example:
  822.  
  823.      switch ( i ) {
  824.        case 1:
  825.          Object obj(0);
  826.              ...
  827.          break;
  828.        case 2:
  829.          ...
  830.          break;
  831.      }
  832.  
  833.    The reason is that `obj' is also in scope in the rest of the switch
  834. statement.
  835.  
  836.    As of version 2.7.0, the compiler will object that the jump to the
  837. second case level crosses the initialization of `obj'.  Older compiler
  838. versions would object only if class Object has a destructor.  In either
  839. case, the solution is to add a set of curly braces around the case
  840. branch:
  841.  
  842.        case 1:
  843.          {
  844.             Object obj(0);
  845.              ...
  846.             break;
  847.          }
  848.  
  849. gcc 2.5.x broke my code!  Changes in function overloading
  850. =========================================================
  851.  
  852.    "I have a program that worked just fine with older g++ versions, but
  853. as of version 2.5.x it doesn't work anymore.  Help!"
  854.  
  855.    While it's always possible that a new bug has been introduced into
  856. the compiler, it's also possible that you have been relying on bugs in
  857. older versions of g++.  For example, version 2.5.0 was the first
  858. version of g++ to correctly implement the "hiding rule."  That is, if
  859. you have an overloaded function in a base class, and in a derived class
  860. you redefine one of the names, the other names are effectively "hidden".
  861. *All* the names from the baseclass need to be redefined in the derived
  862. class.  See section 13.1 of the ARM: "A function member of a derived
  863. class is *not* in the same scope as a function member of the same name
  864. in a base class".
  865.  
  866.    Here's an example that is handled incorrectly by g++ versions before
  867. 2.5.0 and correctly by newer versions:
  868.  
  869.      class Base {
  870.      public:
  871.          void foo(int);
  872.      };
  873.      
  874.      class Derived : public Base {
  875.      public:
  876.          void foo(double);  // *note that Base::foo(int) is hidden*
  877.      };
  878.      
  879.      main() {
  880.          Derived d;
  881.          d.foo(2); // *Derived::foo(double), not Base::foo(int), is called*
  882.      }
  883.  
  884. Where can I find a demangler?
  885. =============================
  886.  
  887.    A g++-compatible demangler named `c++filt' can be found in the
  888. `binutils' distribution.  This distribution (which also contains the
  889. GNU linker) can be found at any GNU archive site.
  890.  
  891.    As of version 2.7.0, `c++filt' is included with gcc and is installed
  892. automatically.  Even better, it is used by the `collect' linker, so you
  893. don't see mangled symbols anymore.
  894.  
  895. Where can I find a version of etags for C++?
  896. ============================================
  897.  
  898.    The libg++ distribution contains a version of etags that works for
  899. C++ code.  Look in `libg++/utils'.  It's not built by default when you
  900. install libg++, but you can cd to that directory and type
  901.  
  902.      make etags
  903.  
  904.    after you've installed libg++.
  905.  
  906. Linker reports undefined symbols for static data members
  907. ========================================================
  908.  
  909.    "g++ reports undefined symbols for all my static data members when I
  910. link, even though the program works correctly for compiler XYZ.  What's
  911. going on?"
  912.  
  913.    The problem is almost certainly that you don't give definitions for
  914. your static data members.  If you have
  915.  
  916.      class Foo {
  917.          ...
  918.          void method();
  919.          static int bar;
  920.      };
  921.  
  922.    you have only declared that there is an int named Foo::bar and a
  923. member function named Foo::method that is defined somewhere.  You still
  924. need to define *both* method() and bar in some source file.  According
  925. to the draft ANSI standard, you must supply an initializer, such as
  926.  
  927.      int Foo::bar = 0;
  928.  
  929. in one (and only one) source file.
  930.  
  931. What does "Internal compiler error" mean?
  932. =========================================
  933.  
  934.    It means that the compiler has detected a bug in itself.
  935. Unfortunately, g++ still has many bugs, though it is a lot better than
  936. it used to be.  If you see this message, please send in a complete bug
  937. report (see next section).
  938.  
  939. I think I have found a bug in g++.
  940. ==================================
  941.  
  942.    "I think I have found a bug in g++, but I'm not sure.  How do I know,
  943. and who should I tell?"
  944.  
  945.    First, see the excellent section on bugs and bug reports in the gcc
  946. manual (which is included in the gcc distribution).  As a short summary
  947. of that section: if the compiler gets a fatal signal, for any input,
  948. it's a bug (newer versions of g++ will ask you to send in a bug report
  949. when they detect an error in themselves).  Same thing for producing
  950. invalid assembly code.
  951.  
  952.    When you report a bug, make sure to describe your platform (the type
  953. of computer, and the version of the operating system it is running) and
  954. the version of the compiler that you are running.  See the output of the
  955. command `g++ -v' if you aren't sure.  Also provide enough code so that
  956. the g++ maintainers can duplicate your bug.  Remember that the
  957. maintainers won't have your header files; one possibility is to send
  958. the output of the preprocessor (use `g++ -E' to get this).  This is
  959. what a "complete bug report" means.
  960.  
  961.    I will add some extra notes that are C++-specific, since the notes
  962. from the gcc documentation are generally C-specific.
  963.  
  964.    First, mail your bug report to "bug-g++@prep.ai.mit.edu".  You may
  965. also post to gnu.g++.bug, but it's better to use mail, particularly if
  966. you have any doubt as to whether your news software generates correct
  967. reply addresses.  Don't mail C++ bugs to bug-gcc@prep.ai.mit.edu.
  968.  
  969.    If your bug involves libg++ rather than the compiler, mail to
  970. bug-lib-g++@prep.ai.mit.edu.  If you're not sure, choose one, and if you
  971. guessed wrong, the maintainers will forward it to the other list.
  972.  
  973.    Second, if your program does one thing, and you think it should do
  974. something else, it is best to consult a good reference if in doubt.
  975. The standard reference is the draft working paper from the ANSI/ISO C++
  976. standardization committee, which you can get on the net.  For
  977. PostScript and PDF (Adobe Acrobat) versions, see the archive at
  978. `ftp://research.att.com/dist/stdc++/WP'.  For HTML and ASCII versions,
  979. see `ftp://ftp.cygnus.com/pub/g++'.  On the World Wide Web, see
  980. `http://www.cygnus.com/~mrs/misc/wp/'.
  981.  
  982.    An older standard reference is "The Annotated C++ Reference Manual",
  983. by Ellis and Stroustrup (copyright 1990, ISBN #0-201-51459-1).  This is
  984. what they're talking about on the net when they refer to "the ARM".
  985. But you should know that changes have been made to the language since
  986. then.
  987.  
  988.    The ANSI/ISO C++ standards committee have adopted some changes to the
  989. C++ language since the publication of the original ARM, and newer
  990. versions of g++ (2.5.x and later) support some of these changes, notably
  991. the mutable keyword (added in 2.5.0), the bool type (added in 2.6.0),
  992. and changes in the scope of variables defined in for statements (added
  993. in 2.7.0).  You can obtain an addendum to the ARM explaining many of
  994. these changes by FTP from
  995. `ftp://ftp.std.com/AW/stroustrup2e/new_iso.ps'.
  996.  
  997.    Note that the behavior of (any version of) AT&T's "cfront" compiler
  998. is NOT the standard for the language.
  999.  
  1000. Porting programs from other compilers to g++
  1001. ============================================
  1002.  
  1003.    "I have a program that runs on <some other C++ compiler>, and I want
  1004. to get it running under g++.  Is there anything I should watch out for?"
  1005.  
  1006.    Note that g++ supports many of the newer keywords that have recently
  1007. been added to the language.  Your other C++ compiler may not support
  1008. them, so you may need to rename variables and members that conflict
  1009. with these keywords.
  1010.  
  1011.    There are two other reasons why a program that worked under one
  1012. compiler might fail under another: your program may depend on the order
  1013. of evaluation of side effects in an expression, or it may depend on the
  1014. lifetime of a temporary (you may be assuming that a temporary object
  1015. "lives" longer than the standard guarantees).  As an example of the
  1016. first:
  1017.  
  1018.      void func(int,int);
  1019.      
  1020.      int i = 3;
  1021.      func(i++,i++);
  1022.  
  1023.    Novice programmers think that the increments will be evaluated in
  1024. strict left-to-right order.  Neither C nor C++ guarantees this; the
  1025. second increment might happen first, for example.  func might get 3,4,
  1026. or it might get 4,3.
  1027.  
  1028.    The second problem often happens with classes like the libg++ String
  1029. class.  Let's say I have
  1030.  
  1031.      String func1();
  1032.      void func2(const char*);
  1033.  
  1034.    and I say
  1035.  
  1036.      func2(func1());
  1037.  
  1038.    because I know that class String has an "operator const char*".  So
  1039. what really happens is
  1040.  
  1041.      func2(func1().convert());
  1042.  
  1043.    where I'm pretending I have a convert() method that is the same as
  1044. the cast.  This is unsafe in g++ versions before 2.6.0, because the
  1045. temporary String object may be deleted after its last use (the call to
  1046. the conversion function), leaving the pointer pointing to garbage, so by
  1047. the time func2 is called, it gets an invalid argument.
  1048.  
  1049.    Both the cfront and the old g++ behaviors are legal according to the
  1050. ARM, but the powers that be have decided that compiler writers were
  1051. given too much freedom here.
  1052.  
  1053.    The ANSI C++ committee has now come to a resolution of the lifetime
  1054. of temporaries problem: they specify that temporaries should be deleted
  1055. at end-of-statement (and at a couple of other points).  This means that
  1056. g++ versions before 2.6.0 now delete temporaries too early, and cfront
  1057. deletes temporaries too late.  As of version 2.6.0, g++ does things
  1058. according to the new standard.
  1059.  
  1060.    For now, the safe way to write such code is to give the temporary a
  1061. name, which forces it to live until the end of the scope of the name.
  1062. For example:
  1063.  
  1064.      String& tmp = func1();
  1065.      func2(tmp);
  1066.  
  1067.    Finally, like all compilers (but especially C++ compilers, it seems),
  1068. g++ has bugs, and you may have tweaked one.  If so, please file a bug
  1069. report (after checking the above issues).
  1070.  
  1071. Why does g++ mangle names differently from other C++ compilers?
  1072. ===============================================================
  1073.  
  1074.    See the answer to the next question.
  1075.  
  1076. Why can't g++ code link with code from other C++ compilers?
  1077. ===========================================================
  1078.  
  1079.    "Why can't I link g++-compiled programs against libraries compiled by
  1080. some other C++ compiler?"
  1081.  
  1082.    Some people think that, if only the FSF and Cygnus Support folks
  1083. would stop being stubborn and mangle names the same way that, say,
  1084. cfront does, then any g++-compiled program would link successfully
  1085. against any cfront-compiled library and vice versa.  Name mangling is
  1086. the least of the problems.  Compilers differ as to how objects are laid
  1087. out, how multiple inheritance is implemented, how virtual function
  1088. calls are handled, and so on, so if the name mangling were made the
  1089. same, your programs would link against libraries provided from other
  1090. compilers but then crash when run.  For this reason, the ARM
  1091. *encourages* compiler writers to make their name mangling different
  1092. from that of other compilers for the same platform.  Incompatible
  1093. libraries are then detected at link time, rather than at run time.
  1094.  
  1095. What documentation exists for g++ 2.x?
  1096. ======================================
  1097.  
  1098.    Relatively little.  While the gcc manual that comes with the
  1099. distribution has some coverage of the C++ part of the compiler, it
  1100. focuses mainly on the C compiler (though the information on the "back
  1101. end" pertains to C++ as well).  Still, there is useful information on
  1102. the command line options and the #pragma interface and #pragma
  1103. implementation directives in the manual, and there is a useful section
  1104. on template instantiation in the 2.6 version.  There is a Unix-style
  1105. manual entry, "g++.1", in the gcc-2.x distribution; the information
  1106. here is a subset of what is in the manual.
  1107.  
  1108.    You can buy a nicely printed and bound copy of this manual from the
  1109. FSF; see above for ordering information.
  1110.  
  1111.    For versions 2.6.2 and later, the gcc/g++ distribution contains the
  1112. gcc manual in PostScript.  Also, Postscript versions of GNU
  1113. documentation in U.S. letter format are available by anonymous FTP from
  1114. `ftp://primus.com/pub/gnu-ps'.  The same, in A4 format, are on
  1115. `ftp://liasun3.epfl.ch/pub/gnu/ps-doc'.
  1116.  
  1117.    A draft of a document describing the g++ internals appears in the gcc
  1118. distribution (called g++int.texi); it is incomplete but gives lots of
  1119. information.
  1120.  
  1121. Problems with the template implementation
  1122. =========================================
  1123.  
  1124.    g++ does not implement a separate pass to instantiate template
  1125. functions and classes at this point; for this reason, it will not work,
  1126. for the most part, to declare your template functions in one file and
  1127. define them in another.  The compiler will need to see the entire
  1128. definition of the function, and will generate a static copy of the
  1129. function in each file in which it is used.
  1130.  
  1131.    (The experimental template repository code (see *Note repository::)
  1132. that can be added to 2.7.0 or later does implement a separate pass, but
  1133. there is still no searching of files that the compiler never saw).
  1134.  
  1135.    For version 2.6.0, however, a new switch `-fno-implicit-templates'
  1136. was added; with this switch, templates are expanded only under user
  1137. control.  I recommend that all g++ users that use templates read the
  1138. section "Template Instantiation" in the gcc manual (version 2.6.x and
  1139. newer).  g++ now supports explicit template expansion using the syntax
  1140. from the latest C++ working paper:
  1141.  
  1142.      template class A<int>;
  1143.      template ostream& operator << (ostream&, const A<int>&);
  1144.  
  1145.    As of version 2.6.3, there are still a few limitations in the
  1146. template implementation besides the above (thanks to Jason Merrill for
  1147. this info):
  1148.  
  1149.   1. Static data member templates are not supported.  You can work
  1150.      around this by explicitly declaring the static variable for each
  1151.      template specialization:
  1152.  
  1153.           template <class T> struct A {
  1154.             static T t;
  1155.           };
  1156.           
  1157.           template <class T> T A<T>::t = 0; // gets bogus error
  1158.           int A<int>::t = 0;                // OK (workaround)
  1159.  
  1160.      (still a limitation in 2.7.0)
  1161.  
  1162.   2. Template member names are not available when defining member
  1163.      function templates.
  1164.  
  1165.           template <class T> struct A {
  1166.             typedef T foo;
  1167.             void f (foo);
  1168.             void g (foo arg) { ... }; // this works
  1169.           };
  1170.           
  1171.           template <class T> void A<T>::f (foo) { } // gets bogus error
  1172.  
  1173.   3. Templates are instantiated using the parser.  This results in two
  1174.      problems:
  1175.  
  1176.      a) Class templates are instantiated in some situations where such
  1177.      instantiation should not occur.
  1178.  
  1179.           template <class T> class A { };
  1180.           A<int> *aip = 0; // should not instantiate A<int> (but does)
  1181.  
  1182.      b) Function templates cannot be inlined at the site of their
  1183.      instantiation.
  1184.  
  1185.           template <class T> inline T min (T a, T b) { return a < b ? a : b; }
  1186.           
  1187.           void f () {
  1188.             int i = min (1, 0);           // not inlined
  1189.           }
  1190.           
  1191.           void g () {
  1192.             int j = min (1, 0);           // inlined
  1193.           }
  1194.  
  1195.      A workaround that works in version 2.6.1 and later is to specify
  1196.  
  1197.           extern template int min (int, int);
  1198.  
  1199.      before `f()'; this will force it to be instantiated (though not
  1200.      emitted).
  1201.  
  1202.   4. Member function templates are always instantiated when their
  1203.      containing class is.  This is wrong.
  1204.  
  1205. I get undefined symbols when using templates
  1206. ============================================
  1207.  
  1208.    (Thanks to Jason Merrill for this section).
  1209.  
  1210.    g++ does not automatically instantiate templates defined in other
  1211. files.  Because of this, code written for cfront will often produce
  1212. undefined symbol errors when compiled with g++.  You need to tell g++
  1213. which template instances you want, by explicitly instantiating them in
  1214. the file where they are defined.  For instance, given the files
  1215.  
  1216.    `templates.h':
  1217.      template <class T>
  1218.      class A {
  1219.      public:
  1220.        void f ();
  1221.        T t;
  1222.      };
  1223.      
  1224.      template <class T> void g (T a);
  1225.  
  1226.    `templates.cc':
  1227.      #include "templates.h"
  1228.      
  1229.      template <class T>
  1230.      void A<T>::f () { }
  1231.      
  1232.      template <class T>
  1233.      void g (T a) { }
  1234.  
  1235.    main.cc:
  1236.      #include "templates.h"
  1237.      
  1238.      main ()
  1239.      {
  1240.        A<int> a;
  1241.        a.f ();
  1242.        g (a);
  1243.      }
  1244.  
  1245.    compiling everything with `g++ main.cc templates.cc' will result in
  1246. undefined symbol errors for `A<int>::f ()' and `g (A<int>)'.  To fix
  1247. these errors, add the lines
  1248.  
  1249.      template class A<int>;
  1250.      template void g (A<int>);
  1251.  
  1252.    to the bottom of `templates.cc' and recompile.
  1253.  
  1254. I get multiply defined symbols using templates
  1255. ==============================================
  1256.  
  1257.    You may be running into a bug that was introduced in version 2.6.1
  1258. (and is still present in 2.6.3) that generated external linkage for
  1259. templates even when neither `-fexternal-templates' nor
  1260. `-fno-implicit-templates' is specified.  There is a patch for this
  1261. problem at
  1262. `ftp://ftp.cygnus.com/pub/g++/gcc-2.6.3-template-fix'.
  1263.  
  1264.    I recommend either applying the patch or using
  1265. `-fno-implicit-templates' together with explicit template instantiation
  1266. as described in previous sections.
  1267.  
  1268.    This bug is fixed in 2.7.0.
  1269.  
  1270. Does g++ support the Standard Template Library?
  1271. ===============================================
  1272.  
  1273.    From Per Bothner:
  1274.  
  1275.    The Standard Template Library (STL) uses many of the extensions that
  1276. the ANSI/ISO committee has made to templates, and g++ doesn't support
  1277. some of these yet.  So if you grab HP's free implementation of STL it
  1278. isn't going to work.  However, libg++-2.6.2 contains a hacked version
  1279. of STL, based on work by Carsten Bormann, which permits gcc-2.6.3 to
  1280. compile at least the containers.  A full implementation is going to
  1281. need improved template support, which will take a while yet.
  1282.  
  1283.    As of libg++-2.7.0 and gcc-2.7.0, I've succeeded in making many short
  1284. STL example programs work, though there are still a number of bugs and
  1285. limitations.  Almost all of the ObjectSpace examples (a set of over 200
  1286. simple examples of STL usage) now work.
  1287.  
  1288.    There are several commercial suppliers of STL implementations;
  1289. ObjectSpace's version supports gcc-2.7.x.
  1290.  
  1291.    Mumit Khan has produced an "STL newbie guide" with lots of
  1292. information on using STL with gcc.  See
  1293.  
  1294.    `http://www.xraylith.wisc.edu/~khan/software/stl/STL.newbie.html'
  1295.  
  1296. What are the differences between g++ and the ARM specification of C++?
  1297. ======================================================================
  1298.  
  1299.    As of version 2.7.0, g++ has exception support on most but not all
  1300. platforms (no support on MIPS-based platforms yet), but it doesn't work
  1301. right if optimizaton is enabled, which means the exception
  1302. implementation is still not really ready for production use.
  1303.  
  1304.    Some features that the ANSI/ISO standardization committee has voted
  1305. in that don't appear in the ARM are supported, notably the `mutable'
  1306. keyword, in version 2.5.x.  2.6.x adds support for the built-in boolean
  1307. type `bool', with constants `true' and `false'.  The beginnings of
  1308. run-time type identification are present, so there are more reserved
  1309. words: `typeid', `static_cast', `reinterpret_cast', `const_cast', and
  1310. `dynamic_cast'.
  1311.  
  1312.    As with any beta-test compiler, there are bugs.  You can help improve
  1313. the compiler by submitting detailed bug reports.
  1314.  
  1315.    One of the weakest areas of g++ other than templates is the
  1316. resolution of overloaded functions and operators in complex cases.  The
  1317. usual symptom is that in a case where the ARM says that it is ambiguous
  1318. which function should be chosen, g++ chooses one (often the first one
  1319. declared).  This is usually not a problem when porting C++ code from
  1320. other compilers to g++, but shows up as errors when code developed under
  1321. g++ is ported to other compilers.  (I believe this is no longer a
  1322. significant problem in 2.7.0).
  1323.  
  1324.    [A full bug list would be very long indeed, so I won't put one here.
  1325. I may add a list of frequently-reported bugs and "non-bugs" like the
  1326. static class members issue mentioned above].
  1327.  
  1328. Will g++ compile InterViews?  The NIH class library?  Rogue Wave?
  1329. =================================================================
  1330.  
  1331.    The NIH class library uses a non-portable, compiler-dependent hack
  1332. to initialize itself, which makes life difficult for g++ users.  It
  1333. will not work without modification, and I don't know what modifications
  1334. are required or whether anyone has done them successfully.
  1335.  
  1336.    In short, it's not going to happen any time soon (previous FAQs
  1337. referred to patches that a new NIHCL release would hopefully contain,
  1338. but this hasn't happened).
  1339.  
  1340.    *Note:* I thought I saw an item indicating that someone *had*
  1341. patched NIHCL to work with g++.  Any pointers?
  1342.  
  1343.    I think that as of version 2.5.6, the standard g++ will compile the
  1344. standard 3.1 InterViews completely successfully.  Note that you'll need
  1345. the `-fno-for-scope' flag if you use gcc-2.7.0; with 2.7.2 you may be
  1346. able to omit this flag but you'll get warnings.
  1347.  
  1348.    According to Jason Merrill, the latest g++ (2.7.0) works with Rogue
  1349. Wave's `tools.h++' class library, but you may want to grab
  1350. `ftp://ftp.cygnus.com/pub/g++/Tools.h++-6.1-patch'.  Again, you'll need
  1351. the `-fno-for-scope' flag since Rogue Wave hasn't fixed their code to
  1352. comply with the new standard yet.
  1353.  
  1354. Debugging on SVR4 systems
  1355. =========================
  1356.  
  1357.    "How do I get debugging to work on my System V Release 4 system?"
  1358.  
  1359.    Most systems based on System V Release 4 (except Solaris) encode
  1360. symbolic debugging information in a format known as `DWARF'.
  1361.  
  1362.    Although the GNU C compiler already knows how to write out symbolic
  1363. debugging information in the DWARF format, the GNU C++ compiler does
  1364. not yet have this feature, nor is it likely to in the immediate future.
  1365.  
  1366.    Ron Guilmette has done a great deal of work to try to get the GNU
  1367. C++ compiler to produce DWARF format symbolic debugging information
  1368. (for C++ code) but he gave up on the project because of a lack of
  1369. funding and/or interest from the g++ user community.  If you have a
  1370. strong desire to see this project completed, contact Ron at
  1371. <rfg@netcom.com>.
  1372.  
  1373.    In the meantime, you *can* get g++ debugging under SVR4 systems by
  1374. configuring gcc with the `--with-stabs' option.  This causes gcc to use
  1375. an alternate debugging format, one more like that used under SunOS4.
  1376. You won't need to do anything special to GDB; it will always understand
  1377. the "stabs" format.
  1378.  
  1379. X11 conflicts with libg++ in definition of String
  1380. =================================================
  1381.  
  1382.    "X11 and Motif define String, and this conflicts with the String
  1383. class in libg++.  How can I use both together?"
  1384.  
  1385.    One possible method is the following:
  1386.  
  1387.      #define String XString
  1388.      #include <X11/Intrinsic.h>
  1389.      /* include other X11 and Motif headers */
  1390.      #undef String
  1391.  
  1392.    and remember to use the correct `String' or `XString' when you
  1393. declare things later.
  1394.  
  1395. Why can't I assign one stream to another?
  1396. =========================================
  1397.  
  1398.    [ Thanks to Per Bothner and Jerry Schwarz for this section. ]
  1399.  
  1400.    Assigning one stream to another seems like a reasonable thing to do,
  1401. but it's a bad idea.  Usually, this comes up because people want to
  1402. assign to `cout'.  This is poor style, especially for libraries, and is
  1403. contrary to good object-oriented design.  (Libraries that write directly
  1404. to `cout' are less flexible, modular, and object-oriented).
  1405.  
  1406.    The iostream classes do not allow assigning to arbitrary streams,
  1407. because this can violate typing:
  1408.  
  1409.      ifstream foo ("foo");
  1410.      istrstream str(...);
  1411.      foo = str;
  1412.      foo->close ();  /* Oops! Not defined for istrstream! */
  1413.  
  1414.    The original cfront implementation of iostreams by Jerry Schwarz
  1415. allows you to assign to `cin', `cout', `cerr', and `clog', but this is
  1416. not part of the draft standard for iostreams and generally isn't
  1417. considered a good idea, so standard-conforming code shouldn't use this
  1418. technique.
  1419.  
  1420.    The GNU implementation of iostream did not support assigning to
  1421. `cin', `cout', `cerr', and `clog' for quite a while, but it now does,
  1422. for backward compatibility with cfront iostream (versions 2.6.1 and
  1423. later of libg++).
  1424.  
  1425.    The ANSI/ISO C++ Working Paper does provide ways of changing the
  1426. streambuf associated with a stream.  Assignment isn't allowed; there is
  1427. an explicit named member that must be used.
  1428.  
  1429.    However, it is not wise to do this, and the results are confusing.
  1430. For example: `fstream::rdbuf' is supposed to return the *original*
  1431. filebuf, not the one you assigned. (This is not yet implemented in GNU
  1432. iostream.)  This must be so because `fstream::rdbuf' is defined to
  1433. return a `filebuf *'.
  1434.  
  1435. What are the rules for shipping code built with g++ and libg++?
  1436. ***************************************************************
  1437.  
  1438.    "Is it is possible to distribute programs for profit that are created
  1439. with g++ and use the g++ libraries?"
  1440.  
  1441.    I am not a lawyer, and this is not legal advice.  In any case, I have
  1442. little interest in telling people how to violate the spirit of the GNU
  1443. licenses without violating the letter.  This section tells you how to
  1444. comply with the intention of the GNU licenses as best I understand them.
  1445.  
  1446.    The FSF has no objection to your making money.  Its only interest is
  1447. that source code to their programs, and libraries, and to modified
  1448. versions of their programs and libraries, is always available.
  1449.  
  1450.    The short answer is that you do not need to release the source to
  1451. your program, but you can't just ship a stripped executable either,
  1452. unless you use only the subset of libg++ that includes the iostreams
  1453. classes (see discussion below) or the new libstdc++ library (available
  1454. in libg++ 2.6.2 and later).
  1455.  
  1456.    Compiling your code with a GNU compiler does not affect its
  1457. copyright; it is still yours.  However, in order to ship code that
  1458. links in a GNU library such as libg++ there are certain rules you must
  1459. follow.  The rules are described in the file COPYING.LIB that
  1460. accompanies gcc distributions; it is also included in the libg++
  1461. distribution.  See that file for the exact rules.  The agreement is
  1462. called the Library GNU Public License or LGPL.  It is much "looser"
  1463. than the GNU Public License, or GPL, that covers must GNU programs.
  1464.  
  1465.    Here's the deal: let's say that you use some version of libg++,
  1466. completely unchanged, in your software, and you want to ship only a
  1467. binary form of your code.  You can do this, but there are several
  1468. special requirements.  If you want to use libg++ but ship only object
  1469. code for your code, you have to ship source for libg++ (or ensure
  1470. somehow that your customer already has the source for the exact version
  1471. you are using), and ship your application in linkable form.  You cannot
  1472. forbid your customer from reverse-engineering or extending your program
  1473. by exploiting its linkable form.
  1474.  
  1475.    Furthermore, if you modify libg++ itself, you must provide source
  1476. for your modifications (making a derived class does not count as
  1477. modifying the library - that is "a work that uses the library").
  1478.  
  1479.    For certain portions of libg++ that implement required parts of the
  1480. C++ language (such as iostreams and other standard classes), the FSF has
  1481. loosened the copyright requirement still more by adding the "special
  1482. exception" clause, which reads as follows:
  1483.  
  1484.      As a special exception, if you link this library with files
  1485.      compiled with GCC to produce an executable, this does not cause
  1486.      the resulting executable to be covered by the GNU General Public
  1487.      License.  This exception does not however invalidate any other
  1488.      reasons why the executable file might be covered by the GNU
  1489.      General Public License.
  1490.  
  1491.    If your only use of libg++ uses code with this exception, you may
  1492. ship stripped executables or license your executables under different
  1493. conditions without fear of violating an FSF copyright.  It is the intent
  1494. of FSF and Cygnus that, as the other classes required by the ANSI/ISO
  1495. draft standard are developed, these will also be placed under this
  1496. "special exception" license.  The code in the new libstdc++ library,
  1497. intended to implement standard classes as defined by ANSI/ISO, is also
  1498. licensed this way.
  1499.  
  1500.    To avoid coming under the influence of the LGPL, you can link with
  1501. `-liostream' rather than `-lg++' (for version 2.6.x and earlier), or
  1502. `-lstdc++' now that it is available.  In version 2.7.0 all the standard
  1503. classes are in `-lstdc++'; you can do the link step with `c++' instead
  1504. of `g++' to search only the `-lstdc++' library and avoid the LGPL'ed
  1505. code in `-lg++'.
  1506.  
  1507. -- 
  1508. -- Joe Buck     <jbuck@synopsys.com>    (not speaking for Synopsys, Inc)
  1509.  
  1510.